<template>
    <view>
        <form @reset="formReset" @submit="formSubmit" :reportSubmit="true">
            <block v-if="szname == 1">
                <view class="weui-cells weui-cells_after-title">
                    <view class="weui-cell">
                        <view class="weui-cell__hd">
                            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/seller/dyj.png"></image>
                        </view>
                        <view class="weui-cell__bd" style="flex: 1">打印设置</view>
                        <picker @change="bindCountryChange" :range="countries" style="flex: 2" :value="countryIndex">
                            <view class="weui-cell__ft"></view>
                        </picker>
                    </view>
                </view>
                <view class="weui-cells weui-cells_after-title">
                    <view class="weui-cell weui-cell_switch">
                        <view class="weui-cell__hd">打印方式</view>
                        <view class="weui-cell__bd">
                            <radio-group class="dyfs" name="radiodyfs">
                                <view class="dyfs">
                                    <view>整单打印</view>
                                    <radio :checked="dyfs" value="1"></radio>
                                </view>
                                <view class="dyfs">
                                    <view>分单打印</view>
                                    <radio :checked="!dyfs" value="2"></radio>
                                </view>
                            </radio-group>
                        </view>
                    </view>
                    <view class="weui-cell weui-cell_switch">
                        <view class="weui-cell__hd">打印时间</view>
                        <view class="weui-cell__bd">
                            <radio-group class="dyfs" name="radiodysj">
                                <view class="dyfs">
                                    <view>下单打印</view>
                                    <radio :checked="dysj" value="1"></radio>
                                </view>
                                <view class="dyfs">
                                    <view>接单打印</view>
                                    <radio :checked="!dysj" value="2"></radio>
                                </view>
                            </radio-group>
                        </view>
                    </view>
                </view>
            </block>
            <block v-if="szname == 2">
                <view class="weui-cells weui-cells_after-title">
                    <view class="weui-cell">
                        <view class="weui-cell__hd">
                            <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/seller/yysj.png"></image>
                        </view>
                        <view class="weui-cell__bd">营业时间</view>
                        <view class="weui-cell__ft"></view>
                    </view>
                </view>
                <view class="weui-cells weui-cells_after-title">
                    <view class="weui-cell weui-cell_switch">
                        <view class="weui-cell__hd">是否营业</view>
                        <view class="weui-cell__bd">
                            <radio-group class="dyfs" name="radiosfyy">
                                <view class="dyfs">
                                    <view>营业</view>
                                    <radio :checked="sfyy" value="2"></radio>
                                </view>
                                <view class="dyfs">
                                    <view>休息</view>
                                    <radio :checked="!sfyy" value="1"></radio>
                                </view>
                            </radio-group>
                        </view>
                    </view>
                </view>
                <view class="weui-cells weui-cells_after-title">
                    <view class="weui-cell weui-cell_input">
                        <view class="weui-cell__hd">
                            <view class="weui-label">上午营业时间</view>
                        </view>
                        <view class="weui-cell__bd">
                            <picker @change="bindTimeChange" mode="time" name="time" :value="time">
                                <view class="weui-input">{{ time }}</view>
                            </picker>
                        </view>
                        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                    </view>
                    <view class="weui-cell weui-cell_input">
                        <view class="weui-cell__hd">
                            <view class="weui-label">上午结束时间</view>
                        </view>
                        <view class="weui-cell__bd">
                            <picker @change="bindTimeChange1" mode="time" name="time1" :value="time1">
                                <view class="weui-input">{{ time1 }}</view>
                            </picker>
                        </view>
                        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                    </view>
                    <view class="weui-cell weui-cell_input">
                        <view class="weui-cell__hd">
                            <view class="weui-label">下午营业时间</view>
                        </view>
                        <view class="weui-cell__bd">
                            <picker @change="bindTimeChange2" mode="time" name="time2" :value="time2">
                                <view class="weui-input">{{ time2 }}</view>
                            </picker>
                        </view>
                        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                    </view>
                    <view class="weui-cell weui-cell_input">
                        <view class="weui-cell__hd">
                            <view class="weui-label">下午结束时间</view>
                        </view>
                        <view class="weui-cell__bd">
                            <picker @change="bindTimeChange3" mode="time" name="time3" :value="time3">
                                <view class="weui-input">{{ time3 }}</view>
                            </picker>
                        </view>
                        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                    </view>
                </view>
            </block>
            <view class="weui-btn-area">
                <button class="weui-btn" formType="submit" :style="'background:' + color" type="primary">提交</button>
            </view>
        </form>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            szname: '',
            storeinfo: '',
            time: '',
            time1: '',
            time2: '',
            time3: '',
            dyfs: false,
            dysj: false,
            sfyy: false,
            countries: [],
            countryIndex: 0,
            color: ''
        };
    },
    onLoad: function (t) {
        var that = this;
        var a = uni.getStorageSync('sjdsjid');
        console.log(t, a);
        this.setData({
            szname: t.szname
        });
        app.globalData.setNavigationBarColor(this);
        app.globalData.util.request({
            url: 'entry/wxapp/StoreInfo',
            cachetime: '0',
            data: {
                store_id: a
            },
            success: function (t) {
                console.log('商家详情', t);
                that.setData({
                    storeinfo: t.data,
                    time: t.data.store.time,
                    time1: t.data.store.time2,
                    time2: t.data.store.time3,
                    time3: t.data.store.time4
                });
                if ('1' == t.data.storeset.print_type) {
                    that.setData({
                        dyfs: true
                    });
                }
                if ('2' == t.data.storeset.print_type) {
                    that.setData({
                        dyfs: false
                    });
                }
                if ('1' == t.data.storeset.print_mode) {
                    that.setData({
                        dysj: true
                    });
                }
                if ('2' == t.data.storeset.print_mode) {
                    that.setData({
                        dysj: false
                    });
                }
                if ('2' == t.data.store.is_rest) {
                    that.setData({
                        sfyy: true
                    });
                }
                if ('1' == t.data.store.is_rest) {
                    that.setData({
                        sfyy: false
                    });
                }
            }
        });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    methods: {
        bindTimeChange: function (t) {
            this.setData({
                time: t.detail.value
            });
        },

        bindTimeChange1: function (t) {
            this.setData({
                time1: t.detail.value
            });
        },

        bindTimeChange2: function (t) {
            this.setData({
                time2: t.detail.value
            });
        },

        bindTimeChange3: function (t) {
            this.setData({
                time3: t.detail.value
            });
        },

        formSubmit: function (t) {
            console.log('form发生了submit事件，携带数据为：', t.detail.value);
            var e = this.szname;
            var a = uni.getStorageSync('sjdsjid');
            console.log(e, a);
            if (1 == e) {
                var i = t.detail.value.radiodyfs;
                var o = t.detail.value.radiodysj;
                console.log(i, o);
                uni.showLoading({
                    title: '提交中',
                    mask: true
                });
                app.globalData.util.request({
                    url: 'entry/wxapp/UpStore',
                    cachetime: '0',
                    data: {
                        store_id: a,
                        print_type: i,
                        print_mode: o
                    },
                    success: function (t) {
                        console.log(t.data);
                        if ('1' == t.data) {
                            uni.showToast({
                                title: '设置成功',
                                icon: 'success',
                                duration: 1000
                            });
                            setTimeout(function () {
                                uni.navigateBack({});
                            }, 1000);
                        } else {
                            if ('2' == t.data) {
                                uni.showToast({
                                    title: '请修改后提交',
                                    icon: 'loading',
                                    duration: 1000
                                });
                            } else {
                                uni.showToast({
                                    title: '请重试',
                                    icon: 'loading',
                                    duration: 1000
                                });
                            }
                        }
                    }
                });
            }
            if (2 == e) {
                var s = t.detail.value.radiosfyy;
                var n = t.detail.value.time;
                var d = t.detail.value.time1;
                var l = t.detail.value.time2;
                var r = t.detail.value.time3;
                console.log(s, n, d, l, r);
                if ('' == n || '' == d || '' == l || '' == r) {
                    return void uni.showModal({
                        title: '提示',
                        content: '时间不能为空'
                    });
                }
                if (d <= n || l <= d) {
                    return void uni.showModal({
                        title: '提示',
                        content: '请设置正确合理的时间'
                    });
                }
                uni.showLoading({
                    title: '提交中',
                    mask: true
                });
                app.globalData.util.request({
                    url: 'entry/wxapp/UpStore',
                    cachetime: '0',
                    data: {
                        store_id: a,
                        is_rest: s,
                        time: n,
                        time2: d,
                        time3: l,
                        time4: r
                    },
                    success: function (t) {
                        console.log(t.data);
                        if ('1' == t.data) {
                            uni.showToast({
                                title: '设置成功',
                                icon: 'success',
                                duration: 1000
                            });
                            setTimeout(function () {
                                uni.navigateBack({});
                            }, 1000);
                        } else {
                            if ('2' == t.data) {
                                uni.showToast({
                                    title: '请修改后提交',
                                    icon: 'loading',
                                    duration: 1000
                                });
                            } else {
                                uni.showToast({
                                    title: '请重试',
                                    icon: 'loading',
                                    duration: 1000
                                });
                            }
                        }
                    }
                });
            }
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        },

        bindCountryChange() {
            console.log('占位：函数 bindCountryChange 未声明');
        }
    }
};
</script>
<style>
@import './dpsz.css';
</style>
